<template>
    <div>
        <Row style="margin-top:20px">
            <Col span="19" class="table-form-input-select-col">
            <span class="alltitle"><router-link to="项目列表"> 项目列表</router-link>>预备员工专区>奖励内容</span>
            </Col>
        </Row>
        <Row class="fazhanlicheng" style="margin-top:20px;height:40px;padding-left:20px">
            <span class="title">入职奖励</span>
        </Row>
        <Row class="fazhanlicheng" style="heigh:60px;padding: 20px">
            <Col class="inner-info2" span="2" offset="1">标题</Col>
            <Col span="18">
                <Input class="time-picker" placeholder="输入规则" style="width: 100%" v-model="title1" />
            </Col>
        </Row>
        <Row class="fazhanlicheng" style="heigh:60px;padding: 20px">
            <Col class="inner-info2" span="2" offset="1">领取规则</Col>
            <Col span="18">
                <Input class="time-picker" placeholder="输入规则" style="width: 100%" v-model="memo1" />
            </Col>
        </Row>
        <Row class="fazhanlicheng" style="heigh:60px;padding: 20px">
            <Col class="inner-info2" span="2" offset="1">内容</Col>
            <Col span="18">
                <Input class="time-picker" type="textarea" :rows="6" placeholder="输入内容" style="width: 100%" v-model="content1" />
            </Col>
        </Row>

        <Row class="fazhanlicheng" style="heigh:60px;">
        </Row>
        <Row class="add-new-progress" style="heigh:60px;background:#f5f7f9">
            <Button type="primary" style="width:100px" @click="commit1">确认提交</Button>
        </Row>

        <Row class="fazhanlicheng" style="margin-top:20px;height:40px;padding-left:20px">
            <span class="title">签到奖励</span>
        </Row>
        <Row class="fazhanlicheng" style="heigh:60px;padding: 20px">
            <Col class="inner-info2" span="2" offset="1">标题</Col>
            <Col span="18">
                <Input class="time-picker" placeholder="输入规则" style="width: 100%" v-model="title2" />
            </Col>
        </Row>
        <Row class="fazhanlicheng" style="heigh:60px;padding: 20px">
            <Col class="inner-info2" span="2" offset="1">领取规则</Col>
            <Col span="18">
                <Input class="time-picker" placeholder="输入规则" style="width: 100%" v-model="memo2" />
            </Col>
        </Row>
        <Row class="fazhanlicheng" style="heigh:60px;padding: 20px">
            <Col class="inner-info2" span="2" offset="1">内容</Col>
            <Col span="18">
                <Input class="time-picker" type="textarea" :rows="6" placeholder="输入内容" style="width: 100%" v-model="content2" />
            </Col>
        </Row>

        <Row class="fazhanlicheng" style="heigh:60px;">
        </Row>
        <Row class="add-new-progress" style="heigh:60px;background:#f5f7f9">
            <Button type="primary" style="width:100px" @click="commit2">确认提交</Button>
        </Row>

    </div>
</template>
<script>
import {
    formatDate
} from '@/js/date.js'
export default {
    data() {
        return {
            data: [],
            title1: "",
            title2: "",
            memo1: "",
            memo2: "",
            content1: '',
            content2: ''
        }
    },

    methods: {
        list() {
            var self = this;
            var poid = localStorage.pid;

            $.ajax({
                url: "https://evp.51job.com/51job/api/1.0/index.php/minirs/award/index",
                data: {
                    "project_id": poid,
                },
                type: "POST",
                dataType: "json",
                success: function(data) {
                    console.log(data);
                    self.data = data.data;
                    if (data.data.length > 0) {
                        self.title1 = data.data[0].title
                        self.memo1 = data.data[0].memo
                        self.content1 = data.data[0].content
                    }
                    if (data.data.length > 1) {
                        self.title2 = data.data[1].title
                        self.memo2 = data.data[1].memo
                        self.content2 = data.data[1].content
                    }
                }
            });
        },
        commit1() {
            if (this.title1.length == 0) {
                self.$Message.error('请输入标题');
                return
            }
            if (this.memo1.length == 0) {
                self.$Message.error('请输入规则');
                return
            }
            if (this.content1.length == 0) {
                self.$Message.error('请输入内容');
                return
            }
            var self = this;
            var poid = localStorage.pid;

            var url = "https://evp.51job.com/51job/api/1.0/index.php/minirs/award/addAward"
            var data = {
                "project_id": poid,
                "title": this.title1,
                "memo": this.memo1,
                "content": this.content1
            }
            if (this.data.length > 0) {
                url = "https://evp.51job.com/51job/api/1.0/index.php/minirs/award/updateAward"
                data.id = this.data[0].id
            }
            $.ajax({
                url: url,
                data: data,
                type: "POST",
                dataType: "json",
                success: function(data) {
                    console.log(data);
                    if (data.code == 1) {
                        self.$Message.success("保存成功！");
                        self.list()
                    }
                }
            });
        },
        commit2() {
            if (this.title2.length == 0) {
                self.$Message.error('请输入标题');
                return
            }
            if (this.memo2.length == 0) {
                self.$Message.error('请输入规则');
                return
            }
            if (this.content2.length == 0) {
                self.$Message.error('请输入内容');
                return
            }
            var self = this;
            var poid = localStorage.pid;

            var url = "https://evp.51job.com/51job/api/1.0/index.php/minirs/award/addAward"
            var data = {
                "project_id": poid,
                "title": this.title2,
                "memo": this.memo2,
                "content": this.content2
            }
            if (this.data.length > 1) {
                url = "https://evp.51job.com/51job/api/1.0/index.php/minirs/award/updateAward"
                data.id = this.data[1].id
            }
            $.ajax({
                url: url,
                data: data,
                type: "POST",
                dataType: "json",
                success: function(data) {
                    console.log(data);
                    if (data.code == 1) {
                        self.$Message.success("保存成功！");
                        self.list()
                    }
                }
            });
        }
    },
    created() {
        var self = this;
        var poid = localStorage.pid;
        self.list();
    }
}
</script>
<style scoped>
.innertitle {
    line-height: 30px;
    font-size: 14px;
    text-decoration: underline;
    color: #4B80FD;
    font-family: MicrosoftYaHei;
    cursor: pointer;
}

.fazhanlicheng {
    box-sizing: border-box;
    background: #fff;
    margin-bottom: 1px;
    padding: 0px;
}

.title {
    font-size: 14px;
    color: #333333;
    letter-spacing: 0;
    line-height: 40px;
    font-weight: bold;
}

.inner-info2 {
    float: left;
    line-height: 60px;
    font-size: 14px;
    color: #333;
    font-family: MicrosoftYaHei;
    margin-right: 10px;
}

.time-picker {
    margin-top: 15px;
}

.add-new-progress {
    box-sizing: border-box;
    background: #fff;
    padding: 0;
    text-align: center;
    color: #4B80FD;
    font-family: SourceHanSansCN-Normal;
    font-size: 14px;
    line-height: 60px;
    cursor: pointer;
}

.img-border {
    border: 1px dashed #d9d9d9;
    background: #e5e5e5;
    display: block;
    width: 60px;
    text-align: center;
    height: 60px;
    line-height: 60px;
    font-size: 50px;
    cursor: pointer;
}

.banner {
    width: 60px;
    text-align: center;
    height: 60px;
}

.avatar-uploader-icon-banner {
    font-size: 28px;
    color: #8c939d;
    width: 167px;
    height: 84px;
    line-height: 84px;
    text-align: center;
    float: left;
    position: relative;
}
</style>
